<?php

/*
 * This is to process on data like insert and update.
 */
include 'users.php';



$action = $_REQUEST['action'];
if ($action == "CREATE_NEW_USER") {
    $user = new Users();
    $user->setFirstName($_REQUEST['fname']);
    $user->setLastName($_REQUEST['lname']);
    $user->setEmail($_REQUEST['email']);
    $type = ($_REQUEST['type'] == NULL) ? "Member" : $_REQUEST['type'];
    $user->setUserType($type);
    $user->setRole($_REQUEST['role']);
    $ban = ($_REQUEST['ban'] == 'true') ? true : false;
    $user->setBan($ban);
    $createUser = Users::createUser($user);
    $createdUser = array();
    if ($createUser == 1) {
        $createUser['status'] = "SUCCESS";
    } else {
        $createUser['status'] = "FAIL";
    }
    $json = json_encode($createUser);
    print_r($json);
} else if ($action == "UPDATE_USER") {
    $user = new Users();
    $user->setId($_REQUEST['id']);
    $user->setFirstName($_REQUEST['fname']);
    $user->setLastName($_REQUEST['lname']);
    $user->setEmail($_REQUEST['email']);
    $type = ($_REQUEST['type'] == NULL) ? "Member" : $_REQUEST['type'];
    $user->setUserType($type);    
    $user->setRole($_REQUEST['role']);
    $ban = ($_REQUEST['ban'] == 'true' || $_REQUEST['ban']==NULL || $_REQUEST['ban']=="") ? true : false;
    $user->setBan($ban);
    //print_r($user);
    $updateUser = Users::updateUser($user);
} else if ($action == "DELETE_USER") {
    $user = new Users();
    $user->setId($_REQUEST['id']);  
    $deleteUser = Users::deleteUser($user);
    print_r($deleteUser);
}
?>
